<div class="easyui-layout" data-options="fit:true">
	<div id="${uuid}-toolbar">
        <div class="wu-toolbar-button">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="${uuid}_add()" plain="true">添加</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="${uuid}_edit()" plain="true">修改</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="${uuid}_remove();" plain="true">删除</a>
        </div>
    </div>
    <table id="${uuid}_tb"></table>
</div>
<div id="${uuid}_dialog_edit" class="easyui-dialog"></div>
<div id="${uuid}_dialog_add" class="easyui-dialog"></div>
<script type="text/javascript">
var productcatenodes=null;
$(function(){
	setTimeout(function(){
		${uuid}_getTree();
	},100);
	
	//$('#wu-datagrid-2').datagrid({data: data}).datagrid('enableCellEditing').datagrid('gotoCell', {    index: 0,    field: 'name'});
});
function ${uuid}_getTree(){
	ajaxLoading();
	$.getJSON('${base}${actionkey}/datagrid',function(data){
		$(".window").hide();
		$(".window-shadow").hide();
		setTimeout(function(){
			ajaxLoadEnd();
		},500);
		var fileds = "id,name,createDate,metaKeywords,metaDescription,orderList,parent_id,";  
		var nodes = ConvertToTreeGridJson(data, "id", "parent_id", fileds);  
		productcatenodes=nodes;
		//var json = JSON.stringify(nodes);
		//console.log(json);
		$('#${uuid}_tb').treegrid({
		    height:550,  
		    rownumbers: true,  
		    animate:true,  
		    idField:'id',//id=productId_propId_largetypeId_midlletypeId_comtypeId;  
		    treeField:'name', 
			columns:[[
						{field:'id',hidden:true}, 
						{
							field:'name',title:'名称',width:200,sortable:true,
						},
						
						
				]],
		});
		$('#${uuid}_tb').treegrid("loadData",nodes);
	});
}
/**
* Name 添加记录
*/
function ${uuid}_add(){
	$('#${uuid}_dialog_edit').dialog({    
	    title: '编辑',    
	    width: 600,    
	    height: 400, 
	    top:80,
	    left:($(window).width()-600)/2,
	    closed: false,    
	    cache: false,
	    minimizable:true,
	    maximizable:true,
	    iconCls:"fa fa-edit",
	    href: '${base}${actionkey}/add',    
	    modal: true,
	    buttons: [{
			text:'提交',
			iconCls:'icon-ok',
			handler:function(){
				$('#${uuid}_edit_form').submit();
			}
		},{
			text:'取消',
			handler:function(){
				$('#${uuid}_dialog_edit').dialog('close'); 
			}
		}],
		onLoad:function(){
			$('#parent_id').combotree({    
			    url: '${base}${actionkey}/getfather'
			}); 
			$('#${uuid}_edit_form').form({    
			    url:'${base}${actionkey}/add',
			    ajax:true,
			    novalidate:true,   
			    success:function(data){ 
			    	data=JSON.parse(data);
			    	toast(data.msg);
			    	if(data.status==1){
			    		${uuid}_getTree();
			    		$('#${uuid}_dialog_edit').dialog('close');
			    	}
			    }    
			}); 
		}
	});	
}

function ${uuid}_edit(){
	var datas=$('#${uuid}_tb').datagrid('getSelections'); 
	console.log(datas);
	if(datas.length>1){
		toast("只能选中一行记录");
		return;
	}
	if(datas.length==0){
		toast("请选择一条记录");
		return;
	}
	$('#${uuid}_dialog_edit').dialog({    
	    title: '编辑',    
	    width: 600,    
	    height: 400, 
	    top:80,
	    left:($(window).width()-600)/2,
	    closed: false,    
	    cache: false,
	    minimizable:true,
	    maximizable:true,
	    iconCls:"fa fa-edit",
	    href: '${base}${actionkey}/modify',    
	    modal: true,
	    buttons: [{
			text:'提交',
			iconCls:'icon-ok',
			handler:function(){
				$('#${uuid}_edit_form').submit();
			}
		},{
			text:'取消',
			handler:function(){
				$('#${uuid}_dialog_edit').dialog('close'); 
			}
		}],
		onLoad:function(){
			$('#parent_id').combotree({    
			    url: '${base}${actionkey}/getfather',
			    onLoadSuccess:function(){
			    	$("#parent_id").combotree("setValue",datas[0].parent_id);
			    }
			});
			$('#${uuid}_edit_form').form('load',datas[0]);
			$('#${uuid}_edit_form').form({    
			    url:'${base}${actionkey}/modify',
			    ajax:true,
			    novalidate:true,   
			    success:function(data){ 
			    	data=JSON.parse(data);
			    	toast(data.msg);
			    	if(data.status==1){
			    		${uuid}_getTree();
			    		$('#${uuid}_dialog_edit').dialog('close'); 
			    	}
			    }    
			}); 
		}
	});	
}

function ${uuid}_remove(){
	var selects=$("#${uuid}_tb").treegrid("getSelected");
	if(selects==null){
		toast("请选择一行");
		return;
	}
	if(selects.length>1){
		toast("只能选中一行");
		return;
	}
	$.messager.confirm('确认对话框', '是否删除该记录？', function(r){
		if (r){
		    $.getJSON('${base}${actionkey}/delete?id='+selects.id,function(data){
		    	toast(data.msg);
		    	if(data.status==1){
		    		${uuid}_getTree();
		    	}
		    });
		}
	});
} 
</script>